<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
use kartik\file\FileInput;
use kartik\editable\Editable;

$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Finances'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;

$orders = $model->order;
?>
<div class="row">
	<div class="col-md-12"><h3 class="page-header"><small>重新提交审批单</small></h3></div>

	<div class="col-md-6" >
		<table class="table table-bordered detail-view">
			<tr>
				<td><?= Yii::t('app.finance', 'Code') ?></td>
				<td><?= $model->code ?></td>
			</tr>
			<tr>
				<td><?= Yii::t('app', 'Type') ?></td>
				<td> 
					<?=  Editable::widget([
    					    'name' => 'Finance[type]',
							'value' => Yii::$app->params['finance_type'][$model->type],
    					    'asPopover' => true,
    					    'header' => '类型',
					    	'inputType' => Editable::INPUT_DROPDOWN_LIST,
					    	'data'=> Yii::$app->params['finance_type'],
    					    'size'=>'md',
    					    'formOptions' => ['action'=>'/finance/finance/edit?id='.$model->id, 'method'=>'get'],
    					    'options' => ['class'=>'form-control', 'placeholder'=>'请选择类型'],
    					    'pluginEvents'=> [],
    					])
					?>
				</td>
			</tr>

			<tr>
				<td><?= Yii::t('app.finance', 'Price Type') ?></td>
				<td>
					<?=  Editable::widget([
    						'name' => 'Finance[price_type]',
							'value' => Yii::$app->params['finance_price_type'][$model->price_type],
    						'asPopover' => true,
    						'header' => '类型',
					    	'inputType' => Editable::INPUT_DROPDOWN_LIST,
					    	'data'=> Yii::$app->params['finance_price_type'],
    						'size'=>'md',
    						'formOptions' => ['action'=>'/finance/finance/edit?id='.$model->id, 'method'=>'get'],
    						'options' => ['class'=>'form-control', 'placeholder'=>'请选择类型'],
    						'pluginEvents'=> [ ],
    					])
					?>
				</td>
			</tr>

			<tr>
				<td><?= Yii::t('app.finance', 'Company') ?></td>
				<td>
					<?=  Editable::widget([
    						'name' => 'Finance[company]',
							'value' => $model->company,
    						'asPopover' => true,
    						'header' => Yii::t('app.finance', 'Company'),
    						'size'=>'md',
    						'formOptions' => ['action'=>'/finance/finance/edit?id='.$model->id, 'method'=>'get'],
    						'options' => ['class'=>'form-control', 'placeholder'=> Yii::t('app.finance', 'Company')],
    						'pluginEvents'=> [ ],
    					])
					?>
				</td>
			</tr>

			<tr>
				<td><?= Yii::t('app.finance', 'Account') ?></td>
				<td>
					<?=  Editable::widget([
    						'name' => 'Finance[account]',
							'value' => $model->account,
    						'asPopover' => true,
    						'header' => Yii::t('app.finance', 'Account'),
    						'size'=>'md',
    						'formOptions' => ['action'=>'/finance/finance/edit?id='.$model->id, 'method'=>'get'],
    						'options' => ['class'=>'form-control', 'placeholder'=> Yii::t('app.finance', 'Account')],
    					])
					?>
				</td>
			</tr>

			<tr>
				<td><?= Yii::t('app.finance', 'Name') ?></td>
				<td>
					<?=  Editable::widget([
    						'name' => 'Finance[name]',
							'value' => $model->name,
    						'asPopover' => true,
    						'header' => Yii::t('app.finance', 'Name'),
    						'size'=>'md',
    						'formOptions' => ['action'=>'/finance/finance/edit?id='.$model->id, 'method'=>'get'],
    						'options' => ['class'=>'form-control', 'placeholder'=> Yii::t('app.finance', 'Name')],
    					])
					?>
				</td>
			</tr>

			<tr>
				<td><?= Yii::t('app.finance', 'Desc') ?></td>
				<td>
					<?=  Editable::widget([
    						'name' => 'Finance[desc]',
							'value' => $model->desc,
    						'asPopover' => true,
    						'header' => Yii::t('app.finance', 'Desc'),
							'inputType' => Editable::INPUT_TEXTAREA,
    						'size'=>'md',
    						'formOptions' => ['action'=>'/finance/finance/edit?id='.$model->id, 'method'=>'get'],
    						'options' => ['class'=>'form-control', 'placeholder'=> Yii::t('app.finance', 'Desc')],
    					])
					?>
				</td>
			</tr>

			<tr>
				<td><?= Yii::t('app', 'Status') ?></td>
				<td><?= yii::$app->params['finance_status'][$model->status] ?></td>
			</tr>

			<tr>
				<td><?= Yii::t('app', 'Created At') ?></td>
				<td><?= $model->created_at ?></td>
			</tr>

			<tr>
				<td><?= Yii::t('app', 'Updated At') ?></td>
				<td><?= \Yii::$app->formatter->asRelativetime($model->updated_at) ?></td>
			</tr>

			<tr>
				<td><?= Yii::t('app.finance', '提交人') ?></td>
				<td><?= $model->user->profile->name?></td>
			</tr>
		</table>
	</div>

	<div class="col-md-6">
    <?php
        echo FileInput::widget([
                       'language' => 'zh',
                       'name' => 'FinanceImg[img]',
                       'id' => 'file-upload',
                       'options' => ['accept' => '', 'multiple'=>true],
                       'pluginOptions' => [
                            'showUpload'  => false,
                            'initialPreview'=> [],
                            'initialPreviewConfig' => [],
                            'showRemove'=> false,
                            'uploadAsync'=> true,
                            'uploadUrl'=>\yii\helpers\Url::to(['/site/finance', 'id'=>$model->id]),
                            'maxFileSize' => 8120,
                            'maxFileCount' => 20,
                       ]
        ]); 
    ?>
		<div style="margin-top:30px;">
		<?php 
			if($model->allImg){
				foreach($model->allImg as $img){
					echo "<a href='/finance/finance/remove-img?id=".$img->id ."' data-confirm='确认删除吗?' >";
					echo  \yii\helpers\Html::img('/'.$img->img, ['width'=>150, 'height'=> 100, 'class'=>'img-thumbnail', 'style'=>'margin-right:10px;']);
					echo "</a>";
				}
			}
		?>
		</div>
	</div>


	<div class="text-danger col-md-12">
		<h4><b>总金额 : <?= Yii::$app->formatter->asCurrency($model->orderPrice) ?></b></h4> 
	</div>

	<div class="col-md-12">
		<div class="panel panel-body">
			<h3><small><a href="/finance/finance/order?id=<?= $model->id ?>" >重新选择关联订单 ,  马上设置</a></small></h3>
		</div>
		<?php if($orders) { ?>
		<h3 class="page-header"><small>关联的订单</small>
			<?= Html::a('重新提交', ['/finance/finance/again-submit', 'id' => $model->id], [
						'class' => 'btn btn-danger btn-sm pull-right',
						'data' => [
							'confirm' => '确定重新提交财务?',
							'method' => 'post',
						],
					])
			?>
		</h3>
		<ul class="list-group">
			<!-- 关联订单 -->
			<?php foreach($orders as $order){ ?>
			<li class="list-group-item">
				<font style="display:inline-block;width:120px;"><?= $order->order->product->code ?></font>
				<a  style="display:inline-block;width:140px;" href="/order/order/view?id=<?= $order->order_id?>" target="_blank" ><?= $order->order->code ?></a>
				<font style="display:inline-block;width:100px;"><?= $order->order->username ?></font>
				<font style="display:inline-block;width:120px;"><?= $order->order->phone ?></font>
				<font style="display:inline-block;width:120px;">
						<?php 
							if($model->status == 1 || $model->status == 4 || $model->status == 5){
								echo Editable::widget([
    		    					'name' => 'Order[price]',
									'value' => $order->price,
									'displayValue' => Yii::$app->formatter->asCurrency($order->price),
    		    					'asPopover' => true,
    		    					'header' => '修改审批金额',
    		    					'size'=>'md',
    		    					'formOptions' => ['action'=>'/finance/finance/edit-price?id='.$order->id, 'method'=>'get'],
    		    					'options' => ['class'=>'form-control', 'placeholder'=>'修改金额'],
    		    					'pluginEvents'=> [
    		    					     "editableSuccess"=>"function(event, val, form, data) { 
											$('#total-price').text(data.total); // 更改订单总金额显示
    		    					     }",
    		    					],
    							]);
							}else{
								echo Yii::$app->formatter->asCurrency($order->price);	
							}
						?>
				</font>
				<font style="display:inline-block;width:100px;">
					<a href="/finance/finance/remove-order?id=<?= $order->id ?>" data-confirm="确认从审批中移除该订单吗?" ><i class="fa fa-remove"></i></a>
				</font>
			</li>
			<?php } ?>
		</ul>
		<?php } ?>
	</div>

</div>

<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">
    /** 图片自动上传 */
    $('#file-upload').on('filebatchselected', function(event, files) {
        $(this).fileinput("upload");
    });

    $('#file-upload').on('fileuploaded', function(event, data, previewId, index) {
        var form = data.form, files = data.files, extra = data.extra,response = data.response, reader = data.reader;
    });

</script>
<?php app\components\JsBlock::end() ?>
